<?php

namespace App\Http\Controllers\Invoice;

use App\Http\Controllers\BaseController;
use App\Http\Validate\Invoice\InvoiceValidate;
use App\Http\Validate\OpenShop\InvestmentPromotion\OrderValidate;
use App\Jobs\OpenShop\PayCsv;
use App\Library\Rms\RmsSysApi;
use App\Service\Invoice\InvoiceService;
use App\Service\OpenShop\OrderService;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Validation\ValidationException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

class MapiController extends BaseController
{

    /**
     * 盟度
     *
     * @param Request $request
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|GuzzleException
     */
    public function callback(Request $request): JsonResponse
    {
        $allData = $request->all();
        Log::info('MapiController_callback', $allData);
        try {
            $params = InvoiceValidate::notifyValidate($allData);
            InvoiceService::notify($params);
            return $this->json(['errcode' => 200, 'msg' => ""]);
        } catch (\Exception $exception) {
            return $this->json(['errcode' => 0, 'msg' => $exception->getMessage()]);
        }

    }
}
